home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209b.zip / octave-2.09 / doc / octave.i09 (.txt) < prev    next >
GNU Info File  |  1997-08-20  |  49KB  |  985 lines

  1. This is Info file octave, produced by Makeinfo-1.64 from the input file
  2. octave.tex.
  3. START-INFO-DIR-ENTRY
  4. * Octave: (octave).     Interactive language for numerical computations.
  5. END-INFO-DIR-ENTRY
  6.    Copyright (C) 1996, 1997 John W. Eaton.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice are
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions.
  17. File: octave,  Node: Filesystem Utilities,  Next: Controlling Subprocesses,  Prev: Timing Utilities,  Up: System Utilities
  18. Filesystem Utilities
  19. ====================
  20.    Octave includes the following functions for renaming and deleting
  21. files, creating, deleting, and reading directories, and for getting
  22. information about the status of files.
  23.  - Built-in Function: [ERR, MSG] = rename (OLD, NEW)
  24.      Change the name of file OLD to NEW.
  25.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  26.      ERR is nonzero and MSG contains a system-dependent error message.
  27.  - Built-in Function: [ERR, MSG] = unlink (FILE)
  28.      Delete FILE.
  29.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  30.      ERR is nonzero and MSG contains a system-dependent error message.
  31.  - Built-in Function: [FILES, ERR, MSG] = readdir (DIR)
  32.      Return names of the files in the directory DIR as an array of
  33.      strings.  If an error occurs, return an empty matrix in FILES.
  34.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  35.      ERR is nonzero and MSG contains a system-dependent error message.
  36.  - Built-in Function: [ERR, MSG] = mkdir (DIR)
  37.      Create a directory named DIR.
  38.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  39.      ERR is nonzero and MSG contains a system-dependent error message.
  40.  - Built-in Function: [ERR, MSG] = rmdir (DIR)
  41.      Remove the directory named DIR.
  42.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  43.      ERR is nonzero and MSG contains a system-dependent error message.
  44.  - Built-in Function: [ERR, MSG] = mkfifo (NAME)
  45.      Create a FIFO special file.
  46.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  47.      ERR is nonzero and MSG contains a system-dependent error message.
  48.  - Built-in Function:  umask (MASK)
  49.      Set the permission mask for file creation.  The parameter MASK is
  50.      interpreted as an octal number.
  51.  - Built-in Function: [INFO, ERR, MSG] = stat (FILE)
  52.  - Built-in Function: [INFO, ERR, MSG] = lstat (FILE)
  53.      Return a structure S containing the following information about
  54.      FILE.
  55.     `dev'
  56.           ID of device containing a directory entry for this file.
  57.     `ino'
  58.           File number of the file.
  59.     `modestr'
  60.           File mode, as a string of ten letters or dashes as would be
  61.           returned by `ls -l'.
  62.     `nlink'
  63.           Number of links.
  64.     `uid'
  65.           User ID of file's owner.
  66.     `gid'
  67.           Group ID of file's group.
  68.     `rdev'
  69.           ID of device for block or character special files.
  70.     `size'
  71.           Size in bytes.
  72.     `atime'
  73.           Time of last access in the same form as time values returned
  74.           from `time'.  *Note Timing Utilities::.
  75.     `mtime'
  76.           Time of last modification in the same form as time values
  77.           returned from `time'.  *Note Timing Utilities::.
  78.     `ctime'
  79.           Time of last file status change in the same form as time
  80.           values returned from `time'.  *Note Timing Utilities::.
  81.     `blksize'
  82.           Size of blocks in the file.
  83.     `blocks'
  84.           Number of blocks allocated for file.
  85.      If the call is successful ERR is 0 and MSG is an empty string.  If
  86.      the file does not exist, or some other error occurs, S is an empty
  87.      matrix, ERR is -1, and MSG contains the corresponding system error
  88.      message.
  89.      If FILE is a symbolic link, `stat' will return information about
  90.      the actual file the is referenced by the link.  Use `lstat' if you
  91.      want information about the symbolic link itself.
  92.      For example,
  93.           [s, err, msg] = stat ("/vmlinuz")
  94.                => s =
  95.                   {
  96.                     atime = 855399756
  97.                     rdev = 0
  98.                     ctime = 847219094
  99.                     uid = 0
  100.                     size = 389218
  101.                     blksize = 4096
  102.                     mtime = 847219094
  103.                     gid = 6
  104.                     nlink = 1
  105.                     blocks = 768
  106.                     modestr = -rw-r--r--
  107.                     ino = 9316
  108.                     dev = 2049
  109.                   }
  110.                => err = 0
  111.                => msg =
  112.  - Built-in Function:  glob (PATTERN)
  113.      Given an array of strings in PATTERN, return the list of file
  114.      names that any of them, or an empty string if no patterns match.
  115.      Tilde expansion is performed on each of the patterns before
  116.      looking for matching file names.  For example,
  117.           glob ("/vm*")
  118.                => "/vmlinuz"
  119.      Note that multiple values are returned in a string matrix with the
  120.      fill character set to ASCII NUL.
  121.  - Built-in Function:  fnmatch (PATTERN, STRING)
  122.      Return 1 or zero for each element of STRING that matches any of
  123.      the elements of the string array PATTERN, using the rules of
  124.      filename pattern matching.  For example,
  125.           fnmatch ("a*b", ["ab"; "axyzb"; "xyzab"])
  126.                => [ 1; 1; 0 ]
  127.  - Built-in Function:  file_in_path (PATH, FILE)
  128.      Return the absolute name name of FILE if it can be found in PATH.
  129.      The value of PATH should be a colon-separated list of directories
  130.      in the format described for the built-in variable `LOADPATH'.
  131.      If the file cannot be found in the path, an empty matrix is
  132.      returned.  For example,
  133.           file_in_path (LOADPATH, "nargchk.m")
  134.                => "/share/octave/2.0/m/general/nargchk.m"
  135.  - Built-in Function:  tilde_expand (STRING)
  136.      Performs tilde expansion on STRING.  If STRING begins with a tilde
  137.      character, (`~'), all of the characters preceding the first slash
  138.      (or all characters, if there is no slash) are treated as a
  139.      possible user name, and the tilde and the following characters up
  140.      to the slash are replaced by the home directory of the named user.
  141.      If the tilde is followed immediately by a slash, the tilde is
  142.      replaced by the home directory of the user running Octave.  For
  143.      example,
  144.           tilde_expand ("~joeuser/bin")
  145.                => "/home/joeuser/bin"
  146.           tilde_expand ("~/bin")
  147.                => "/home/jwe/bin"
  148. File: octave,  Node: Controlling Subprocesses,  Next: Process ID Information,  Prev: Filesystem Utilities,  Up: System Utilities
  149. Controlling Subprocesses
  150. ========================
  151.    Octave includes some high-level commands like `system' and `popen'
  152. for starting subprocesses.  If you want to run another program to
  153. perform some task and then look at its output, you will probably want
  154. to use these functions.
  155.    Octave also provides several very low-level Unix-like functions which
  156. can also be used for starting subprocesses, but you should probably only
  157. use them if you can't find any way to do what you need with the
  158. higher-level functions.
  159.  - Built-in Function:  system (STRING, RETURN_OUTPUT, TYPE)
  160.      Execute a shell command specified by STRING.  The second argument
  161.      is optional.  If TYPE is `"async"', the process is started in the
  162.      background and the process id of the child process is returned
  163.      immediately.  Otherwise, the process is started, and Octave waits
  164.      until it exits.  If TYPE argument is omitted, a value of `"sync"'
  165.      is assumed.
  166.      If two input arguments are given (the actual value of
  167.      RETURN_OUTPUT is irrelevant) and the subprocess is started
  168.      synchronously, or if SYSTEM is called with one input argument and
  169.      one or more output arguments, the output from the command is
  170.      returned.  Otherwise, if the subprocess is executed synchronously,
  171.      it's output is sent to the standard output.  To send the output of
  172.      a command executed with SYSTEM through the pager, use a command
  173.      like
  174.           disp (system (cmd, 1));
  175.      or
  176.           printf ("%s\n", system (cmd, 1));
  177.      The `system' function can return two values.  The first is any
  178.      output from the command that was written to the standard output
  179.      stream, and the second is the output status of the command.  For
  180.      example,
  181.           [output, status] = system ("echo foo; exit 2");
  182.      will set the variable `output' to the string `foo', and the
  183.      variable `status' to the integer `2'.
  184.  - Built-in Function: fid = popen (COMMAND, MODE)
  185.      Start a process and create a pipe.  The name of the command to run
  186.      is given by COMMAND.  The file identifier corresponding to the
  187.      input or output stream of the process is returned in FID.  The
  188.      argument MODE may be
  189.     `"r"'
  190.           The pipe will be connected to the standard output of the
  191.           process, and open for reading.
  192.     `"w"'
  193.           The pipe will be connected to the standard input of the
  194.           process, and open for writing.
  195.      For example,
  196.           fid = popen ("ls -ltr / | tail -3", "r");
  197.           while (isstr (s = fgets (fid)))
  198.             fputs (stdout, s);
  199.           endwhile
  200.                -| drwxr-xr-x  33 root  root  3072 Feb 15 13:28 etc
  201.                -| drwxr-xr-x   3 root  root  1024 Feb 15 13:28 lib
  202.                -| drwxrwxrwt  15 root  root  2048 Feb 17 14:53 tmp
  203.  - Built-in Function:  pclose (FID)
  204.      Close a file identifier that was opened by `popen'.  You may also
  205.      use `fclose' for the same purpose.
  206.  - Built-in Function: [IN, OUT, PID] = popen2 (COMMAND, ARGS)
  207.      Start a subprocess with two-way communication.  The name of the
  208.      process is given by COMMAND, and ARGS is an array of strings
  209.      containing options for the command.  The file identifiers for the
  210.      input and output streams of the subprocess are returned in IN and
  211.      OUT.  If execution of the command is successful, PID contains the
  212.      process ID of the subprocess.  Otherwise, PID is -1.
  213.      For example,
  214.           [in, out, pid] = popen2 ("sort", "-nr");
  215.           fputs (in, "these\nare\nsome\nstrings\n");
  216.           fclose (in);
  217.           while (isstr (s = fgets (out)))
  218.             fputs (stdout, s);
  219.           endwhile
  220.           fclose (out);
  221.                -| are
  222.                -| some
  223.                -| strings
  224.                -| these
  225.  - Built-in Variable: EXEC_PATH
  226.      The variable `EXEC_PATH' is a colon separated list of directories
  227.      to search when executing subprograms.  Its initial value is taken
  228.      from the environment variable `OCTAVE_EXEC_PATH' (if it exists) or
  229.      `PATH', but that value can be overridden by the the command line
  230.      argument `--exec-path PATH', or by setting the value of
  231.      `EXEC_PATH' in a startup script.  If the value of `EXEC_PATH'
  232.      begins (ends) with a colon, the directories
  233.           OCTAVE-HOME/libexec/octave/site/exec/ARCH
  234.           OCTAVE-HOME/libexec/octave/VERSION/exec/ARCH
  235.      are prepended (appended) to `EXEC_PATH', where OCTAVE-HOME is the
  236.      top-level directory where all of Octave is installed (the default
  237.      value is `').  If you don't specify a value for `EXEC_PATH'
  238.      explicitly, these special directories are prepended to your shell
  239.      path.
  240.    In most cases, the following functions simply decode their arguments
  241. and make the corresponding Unix system calls.  For a complete example
  242. of how they can be used, look at the definition of the function
  243. `popen2'.
  244.  - Built-in Function: [PID, MSG] = fork ()
  245.      Create a copy of the current process.
  246.      Fork can return one of the following values:
  247.     > 0
  248.           You are in the parent process.  The value returned from
  249.           `fork' is the process id of the child process.  You should
  250.           probably arrange to wait for any child processes to exit.
  251.     0
  252.           You are in the child process.  You can call `exec' to start
  253.           another process.  If that fails, you should probably call
  254.           `exit'.
  255.     < 0
  256.           The call to `fork' failed for some reason.  You must take
  257.           evasive action.  A system dependent error message will be
  258.           waiting in MSG.
  259.  - Built-in Function: [ERR, MSG] = exec (FILE, ARGS)
  260.      Replace current process with a new process.  Calling `exec' without
  261.      first calling `fork' will terminate your current Octave process and
  262.      replace it with the program named by FILE.  For example,
  263.           exec ("ls" "-l")
  264.      will run `ls' and return you to your shell prompt.
  265.      If successful, `exec' does not return.  If `exec' does return, ERR
  266.      will be nonzero, and MSG will contain a system-dependent error
  267.      message.
  268.  - Built-in Function: [FILE_IDS, ERR, MSG] = pipe ()
  269.      Create a pipe and return the vector FILE_IDS, which corresponding
  270.      to the reading and writing ends of the pipe.
  271.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  272.      ERR is nonzero and MSG contains a system-dependent error message.
  273.  - Built-in Function: [FID, MSG] = dup2 (OLD, NEW)
  274.      Duplicate a file descriptor.
  275.      If successful, FID is greater than zero and contains the new file
  276.      ID.  Otherwise, FID is negative and MSG contains a
  277.      system-dependent error message.
  278.  - Built-in Function: [PID, MSG] = waitpid (PID, OPTIONS)
  279.      Wait for process PID to terminate.  The PID argument can be:
  280.     -1
  281.           Wait for any child process.
  282.     0
  283.           Wait for any child process whose process group ID is equal to
  284.           that of the Octave interpreter process.
  285.     > 0
  286.           Wait for termination of the child process with ID PID.
  287.      The OPTIONS argument can be:
  288.     0
  289.           Wait until signal is received or a child process exits (this
  290.           is the default if the OPTIONS argument is missing).
  291.     1
  292.           Do not hang if status is not immediately available.
  293.     2
  294.           Report the status of any child processes that are stopped,
  295.           and whose status has not yet been reported since they stopped.
  296.     3
  297.           Implies both 1 and 2.
  298.      If the returned value of PID is greater than 0, it is the process
  299.      ID of the child process that exited.  If an error occurs, PID will
  300.      be less than zero and MSG will contain a system-dependent error
  301.      message.
  302.  - Built-in Function: [ERR, MSG] = fcntl (FID, REQUEST, ARG)
  303.      Change the properties of the open file FID.  The following values
  304.      may be passed as REQUEST:
  305.     `F_DUPFD'
  306.           Return a duplicate file descriptor.
  307.     `F_GETFD'
  308.           Return the file descriptor flags for FID.
  309.     `F_SETFD'
  310.           Set the file descriptor flags for FID.
  311.     `F_GETFL'
  312.           Return the file status flags for FID.  The following codes
  313.           may be returned (some of the flags may be undefined on some
  314.           systems).
  315.          `O_RDONLY'
  316.                Open for reading only.
  317.          `O_WRONLY'
  318.                Open for writing only.
  319.          `O_RDWR'
  320.                Open for reading and writing.
  321.          `O_APPEND'
  322.                Append on each write.
  323.          `O_NONBLOCK'
  324.                Nonblocking mode.
  325.          `O_SYNC'
  326.                Wait for writes to complete.
  327.          `O_ASYNC'
  328.                Asynchronous I/O.
  329.     `F_SETFL'
  330.           Set the file status flags for FID to the value specified by
  331.           ARG.  The only flags that can be changed are `O_APPEND' and
  332.           `O_NONBLOCK'.
  333.      If successful, ERR is 0 and MSG is an empty string.  Otherwise,
  334.      ERR is nonzero and MSG contains a system-dependent error message.
  335. File: octave,  Node: Process ID Information,  Next: Environment Variables,  Prev: Controlling Subprocesses,  Up: System Utilities
  336. Process, Group, and User IDs
  337. ============================
  338.  - Built-in Function:  getpgrp ()
  339.      Return the process group id of the current process.
  340.  - Built-in Function:  getpid ()
  341.      Return the process id of the current process.
  342.  - Built-in Function:  getppid ()
  343.      Return the process id of the parent process.
  344.  - Built-in Function:  geteuid ()
  345.      Return the effective user id of the current process.
  346.  - Built-in Function:  getuid ()
  347.      Return the real user id of the current process.
  348.  - Built-in Function:  getegid ()
  349.      Return the effective group id of the current process.
  350.  - Built-in Function:  getgid ()
  351.      Return the real group id of the current process.
  352. File: octave,  Node: Environment Variables,  Next: Current Working Directory,  Prev: Process ID Information,  Up: System Utilities
  353. Environment Variables
  354. =====================
  355.  - Built-in Function:  getenv (VAR)
  356.      Return the value of the environment variable VAR.  For example,
  357.           getenv ("PATH")
  358.      returns a string containing the value of your path.
  359.  - Built-in Function:  putenv (VAR, VALUE)
  360.      Set the value of the environment variable VAR to VALUE.
  361. File: octave,  Node: Current Working Directory,  Next: Password Database Functions,  Prev: Environment Variables,  Up: System Utilities
  362. Current Working Directory
  363. =========================
  364.  - Command: cd DIR
  365.  - Command: chdir DIR
  366.      Change the current working directory to DIR.  For example,
  367.           cd ~/octave
  368.      Changes the current working directory to `~/octave'.  If the
  369.      directory does not exist, an error message is printed and the
  370.      working directory is not changed.
  371.  - Built-in Function:  pwd ()
  372.      Return the current working directory.
  373.  - Built-in Variable: PWD
  374.      The current working directory.  The value of `PWD' is updated each
  375.      time the current working directory is changed with the `cd'
  376.      command.
  377.  - Command: ls OPTIONS
  378.  - Command: dir OPTIONS
  379.      List directory contents.  For example,
  380.           ls -l
  381.                -| total 12
  382.                -| -rw-r--r--   1 jwe  users  4488 Aug 19 04:02 foo.m
  383.                -| -rw-r--r--   1 jwe  users  1315 Aug 17 23:14 bar.m
  384.      The `dir' and `ls' commands are implemented by calling your
  385.      system's directory listing command, so the available options may
  386.      vary from system to system.
  387. File: octave,  Node: Password Database Functions,  Next: Group Database Functions,  Prev: Current Working Directory,  Up: System Utilities
  388. Password Database Functions
  389. ===========================
  390.    Octave's password database functions return information in a
  391. structure with the following fields.
  392. `name'
  393.      The user name.
  394. `passwd'
  395.      The encrypted password, if available.
  396. `uid'
  397.      The numeric user id.
  398. `gid'
  399.      The numeric group id.
  400. `gecos'
  401.      The GECOS field.
  402. `dir'
  403.      The home directory.
  404. `shell'
  405.      The initial shell.
  406.    In the descriptions of the following functions, this data structure
  407. is referred to as a PW_STRUCT.
  408.  - Loadable Function: PW_STRUCT =  getpwent ()
  409.      Return a structure containing an entry from the password database,
  410.      opening it if necessary. Once the end of the data has been reached,
  411.      `getpwent' returns 0.
  412.  - Loadable Function: PW_STRUCT =  getpwuid (UID).
  413.      Return a structure containing the first entry from the password
  414.      database with the user ID UID.  If the user ID does not exist in
  415.      the database, `getpwuid' returns 0.
  416.  - Loadable Function: PW_STRUCT =  getpwnam (NAME)
  417.      Return a structure containing the first entry from the password
  418.      database with the user name NAME.  If the user name does not exist
  419.      in the database, `getpwname' returns 0.
  420.  - Loadable Function:  setpwent ()
  421.      Return the internal pointer to the beginning of the password
  422.      database.
  423.  - Loadable Function:  endpwent ()
  424.      Close the password database.
  425. File: octave,  Node: Group Database Functions,  Next: System Information,  Prev: Password Database Functions,  Up: System Utilities
  426. Group Database Functions
  427. ========================
  428.    Octave's group database functions return information in a structure
  429. with the following fields.
  430. `name'
  431.      The user name.
  432. `passwd'
  433.      The encrypted password, if available.
  434. `gid'
  435.      The numeric group id.
  436. `mem'
  437.      The members of the group.
  438.    In the descriptions of the following functions, this data structure
  439. is referred to as a GRP_STRUCT.
  440.  - Loadable Function: GRP_STRUCT = getgrent ()
  441.      Return an entry from the group database, opening it if necessary.
  442.      Once the end of the data has been reached, `getgrent' returns 0.
  443.  - Loadable Function: GRP_STRUCT = getgrgid (GID).
  444.      Return the first entry from the group database with the group ID
  445.      GID.  If the group ID does not exist in the database, `getgrgid'
  446.      returns 0.
  447.  - Loadable Function: GRP_STRUCT = getgrnam (NAME)
  448.      Return the first entry from the group database with the group name
  449.      NAME.  If the group name does not exist in the database,
  450.      `getgrname' returns 0.
  451.  - Loadable Function:  setgrent ()
  452.      Return the internal pointer to the beginning of the group database.
  453.  - Loadable Function:  endgrent ()
  454.      Close the group database.
  455. File: octave,  Node: System Information,  Prev: Group Database Functions,  Up: System Utilities
  456. System Information
  457. ==================
  458.  - Built-in Function:  computer ()
  459.      Print or return a string of the form CPU-VENDOR-OS that identifies
  460.      the kind of computer Octave is running on.  If invoked with an
  461.      output argument, the value is returned instead of printed.  For
  462.      example,
  463.           computer ()
  464.                -| i586-pc-linux-gnu
  465.           
  466.           x = computer ()
  467.                => x = "i586-pc-linux-gnu"
  468.  - Built-in Function:  isieee ()
  469.      Return 1 if your computer claims to conform to the IEEE standard
  470.      for floating point calculations.
  471.  - Built-in Function:  version ()
  472.      Return Octave's version number as a string.  This is also the
  473.      value of the built-in variable `OCTAVE_VERSION'.
  474.  - Built-in Variable: OCTAVE_VERSION
  475.      The version number of Octave, as a string.
  476.  - Built-in Function:  octave_config_info ()
  477.      Return a structure containing configuration and installation
  478.      information.
  479.  - Loadable Function:  getrusage ()
  480.      Return a structure containing a number of statistics about the
  481.      current Octave process.  Not all fields are available on all
  482.      systems.  If it is not possible to get CPU time statistics, the
  483.      CPU time slots are set to zero.  Other missing data are replaced
  484.      by NaN.  Here is a list of all the possible fields that can be
  485.      present in the structure returned by `getrusage':
  486.     `'
  487.     `idrss'
  488.           Unshared data size.
  489.     `inblock'
  490.           Number of block input operations.
  491.     `isrss'
  492.           Unshared stack size.
  493.     `ixrss'
  494.           Shared memory size.
  495.     `majflt'
  496.           Number of major page faults.
  497.     `maxrss'
  498.           Maximum data size.
  499.     `minflt'
  500.           Number of minor page faults.
  501.     `msgrcv'
  502.           Number of messages received.
  503.     `msgsnd'
  504.           Number of messages sent.
  505.     `nivcsw'
  506.           Number of involuntary context switches.
  507.     `nsignals'
  508.           Number of signals received.
  509.     `nswap'
  510.           Number of swaps.
  511.     `nvcsw'
  512.           Number of voluntary context switches.
  513.     `oublock'
  514.           Number of block output operations.
  515.     `stime'
  516.           A structure containing the system CPU time used.  The
  517.           structure has the elements `sec' (seconds) `usec'
  518.           (microseconds).
  519.     `utime'
  520.           A structure containing the user CPU time used.  The structure
  521.           has the elements `sec' (seconds) `usec' (microseconds).
  522. File: octave,  Node: Tips,  Next: Trouble,  Prev: System Utilities,  Up: Top
  523. Tips and Standards
  524. ******************
  525.    This chapter describes no additional features of Octave.  Instead it
  526. gives advice on making effective use of the features described in the
  527. previous chapters.
  528. * Menu:
  529. * Style Tips::                  Writing clean and robust programs.
  530. * Coding Tips::                 Making code run faster.
  531. * Documentation Tips::          Writing readable documentation strings.
  532. * Comment Tips::                Conventions for writing comments.
  533. * Function Headers::            Standard headers for functions.
  534. File: octave,  Node: Style Tips,  Next: Coding Tips,  Prev: Tips,  Up: Tips
  535. Writing Clean Octave Programs
  536. =============================
  537.    Here are some tips for avoiding common errors in writing Octave code
  538. intended for widespread use:
  539.    * Since all global variables share the same name space, and all
  540.      functions share another name space, you should choose a short word
  541.      to distinguish your program from other Octave programs.  Then take
  542.      care to begin the names of all global variables, constants, and
  543.      functions with the chosen prefix.  This helps avoid name conflicts.
  544.      If you write a function that you think ought to be added to Octave
  545.      under a certain name, such as `fiddle_matrix', don't call it by
  546.      that name in your program.  Call it `mylib_fiddle_matrix' in your
  547.      program, and send mail to (bug-octave@bevo.che.wisc.edu)
  548.      suggesting that it be added to Octave.  If and when it is, the
  549.      name can be changed easily enough.
  550.      If one prefix is insufficient, your package may use two or three
  551.      alternative common prefixes, so long as they make sense.
  552.      Separate the prefix from the rest of the symbol name with an
  553.      underscore `_'.  This will be consistent with Octave itself and
  554.      with most Octave programs.
  555.    * When you encounter an error condition, call the function `error'
  556.      (or `usage').  The `error' and `usage' functions do not return.
  557.      *Note Errors::.
  558.    * Please put a copyright notice on the file if you give copies to
  559.      anyone.  Use the same lines that appear at the top of the function
  560.      files distributed with Octave.  If you have not signed papers to
  561.      assign the copyright to anyone else, then place your name in the
  562.      copyright notice.
  563. File: octave,  Node: Coding Tips,  Next: Documentation Tips,  Prev: Style Tips,  Up: Tips
  564. Tips for Making Code Run Faster.
  565. ================================
  566.    Here are some ways of improving the execution speed of Octave
  567. programs.
  568.    * Avoid looping wherever possible.
  569.    * Use iteration rather than recursion whenever possible.  Function
  570.      calls are slow in Octave.
  571.    * Avoid resizing matrices unnecessarily.  When building a single
  572.      result matrix from a series of calculations, set the size of the
  573.      result matrix first, then insert values into it.  Write
  574.           result = zeros (big_n, big_m)
  575.           for i = over:and_over
  576.             r1 = ...
  577.             r2 = ...
  578.             result (r1, r2) = new_value ();
  579.           endfor
  580.      instead of
  581.           result = [];
  582.           for i = ever:and_ever
  583.             result = [ result, new_value() ];
  584.           endfor
  585.    * Avoid calling `eval' or `feval' whenever possible, because they
  586.      require Octave to parse input or look up the name of a function in
  587.      the symbol table.
  588.      If you are using `eval' as an exception handling mechanism and not
  589.      because you need to execute some arbitrary text, use the `try'
  590.      statement instead.  *Note The try Statement::.
  591.    * If you are calling lots of functions but none of them will need to
  592.      change during your run, set the variable
  593.      `ignore_function_time_stamp' to `"all"' so that Octave doesn't
  594.      waste a lot of time checking to see if you have updated your
  595.      function files.
  596. File: octave,  Node: Documentation Tips,  Next: Comment Tips,  Prev: Coding Tips,  Up: Tips
  597. Tips for Documentation Strings
  598. ==============================
  599.    Here are some tips for the writing of documentation strings.
  600.    * Every command, function, or variable intended for users to know
  601.      about should have a documentation string.
  602.    * An internal variable or subroutine of an Octave program might as
  603.      well have a documentation string.
  604.    * The first line of the documentation string should consist of one
  605.      or two complete sentences that stand on their own as a summary.
  606.      The documentation string can have additional lines that expand on
  607.      the details of how to use the function or variable.  The
  608.      additional lines should also be made up of complete sentences.
  609.    * For consistency, phrase the verb in the first sentence of a
  610.      documentation string as an infinitive with "to" omitted.  For
  611.      instance, use "Return the frob of A and B." in preference to
  612.      "Returns the frob of A and B
  613. "  Usually it looks good to do
  614.      likewise for the rest of the first paragraph.  Subsequent
  615.      paragraphs usually look better if they have proper subjects.
  616.    * Write documentation strings in the active voice, not the passive,
  617.      and in the present tense, not the future.  For instance, use
  618.      "Return a list containing A and B." instead of "A list containing
  619.      A and B will be returned."
  620.    * Avoid using the word "cause" (or its equivalents) unnecessarily.
  621.      Instead of, "Cause Octave to display text in boldface," write just
  622.      "Display text in boldface."
  623.    * Do not start or end a documentation string with whitespace.
  624.    * Format the documentation string so that it fits in an Emacs window
  625.      on an 80-column screen.  It is a good idea for most lines to be no
  626.      wider than 60 characters.
  627.      However, rather than simply filling the entire documentation
  628.      string, you can make it much more readable by choosing line breaks
  629.      with care.  Use blank lines between topics if the documentation
  630.      string is long.
  631.    * *Do not* indent subsequent lines of a documentation string so that
  632.      the text is lined up in the source code with the text of the first
  633.      line.  This looks nice in the source code, but looks bizarre when
  634.      users view the documentation.  Remember that the indentation
  635.      before the starting double-quote is not part of the string!
  636.    * The documentation string for a variable that is a yes-or-no flag
  637.      should start with words such as "Nonzero means...", to make it
  638.      clear that all nonzero values are equivalent and indicate
  639.      explicitly what zero and nonzero mean.
  640.    * When a function's documentation string mentions the value of an
  641.      argument of the function, use the argument name in capital letters
  642.      as if it were a name for that value.  Thus, the documentation
  643.      string of the operator `/' refers to its second argument as
  644.      `DIVISOR', because the actual argument name is `divisor'.
  645.      Also use all caps for meta-syntactic variables, such as when you
  646.      show the decomposition of a list or vector into subunits, some of
  647.      which may vary.
  648. File: octave,  Node: Comment Tips,  Next: Function Headers,  Prev: Documentation Tips,  Up: Tips
  649. Tips on Writing Comments
  650. ========================
  651.    Here are the conventions to follow when writing comments.
  652.      Comments that start with a single sharp-sign, `#', should all be
  653.      aligned to the same column on the right of the source code.  Such
  654.      comments usually explain how the code on the same line does its
  655.      job.  In the Emacs mode for Octave, the `M-;'
  656.      (`indent-for-comment') command automatically inserts such a `#' in
  657.      the right place, or aligns such a comment if it is already present.
  658.      Comments that start with two semicolons, `##', should be aligned to
  659.      the same level of indentation as the code.  Such comments usually
  660.      describe the purpose of the following lines or the state of the
  661.      program at that point.
  662. The indentation commands of the Octave mode in Emacs, such as `M-;'
  663. (`indent-for-comment') and `TAB' (`octave-indent-line') automatically
  664. indent comments according to these conventions, depending on the number
  665. of semicolons.  *Note Manipulating Comments: (emacs)Comments.
  666. File: octave,  Node: Function Headers,  Prev: Comment Tips,  Up: Tips
  667. Conventional Headers for Octave Functions
  668. =========================================
  669.    Octave has conventions for using special comments in function files
  670. to give information such as who wrote them.  This section explains these
  671. conventions.
  672.    The top of the file should contain a copyright notice, followed by a
  673. block of comments that can be used as the help text for the function.
  674. Here is an example:
  675.      ## Copyright (C) 1996, 1997 John W. Eaton
  676.      ##
  677.      ## This file is part of Octave.
  678.      ##
  679.      ## Octave is free software; you can redistribute it and/or
  680.      ## modify it under the terms of the GNU General Public
  681.      ## License as published by the Free Software Foundation;
  682.      ## either version 2, or (at your option) any later version.
  683.      ##
  684.      ## Octave is distributed in the hope that it will be useful,
  685.      ## but WITHOUT ANY WARRANTY; without even the implied
  686.      ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  687.      ## PURPOSE.  See the GNU General Public License for more
  688.      ## details.
  689.      ##
  690.      ## You should have received a copy of the GNU General Public
  691.      ## License along with Octave; see the file COPYING.  If not,
  692.      ## write to the Free Software Foundation, 59 Temple Place -
  693.      ## Suite 330, Boston, MA 02111-1307, USA.
  694.      
  695.      ## usage: [IN, OUT, PID] = popen2 (COMMAND, ARGS)
  696.      ##
  697.      ## Start a subprocess with two-way communication.  COMMAND
  698.      ## specifies the name of the command to start.  ARGS is an
  699.      ## array of strings containing options for COMMAND.  IN and
  700.      ## OUT are the file ids of the input and streams for the
  701.      ## subprocess, and PID is the process id of the subprocess,
  702.      ## or -1 if COMMAND could not be executed.
  703.      ##
  704.      ## Example:
  705.      ##
  706.      ##  [in, out, pid] = popen2 ("sort", "-nr");
  707.      ##  fputs (in, "these\nare\nsome\nstrings\n");
  708.      ##  fclose (in);
  709.      ##  while (isstr (s = fgets (out)))
  710.      ##    fputs (stdout, s);
  711.      ##  endwhile
  712.      ##  fclose (out);
  713.    Octave uses the first block of comments in a function file that do
  714. not appear to be a copyright notice as the help text for the file.  For
  715. Octave to recognize the first comment block as a copyright notice, it
  716. must match the regular expression
  717.      ^ Copyright (C).*\n\n This file is part of Octave.
  718.      ^ Copyright (C).*\n\n This program is free softwar
  719. (after stripping the leading comment characters).  This is a fairly
  720. strict requirement, and may be relaxed somewhat in the future.
  721.    After the copyright notice and help text come several "header
  722. comment" lines, each beginning with `## HEADER-NAME:'.  For example,
  723.      ## Author: jwe
  724.      ## Keywords: subprocesses input-output
  725.      ## Maintainer: jwe
  726.    Here is a table of the conventional possibilities for HEADER-NAME:
  727. `Author'
  728.      This line states the name and net address of at least the principal
  729.      author of the library.
  730.           ## Author: John W. Eaton <jwe@bevo.che.wsic.edu>
  731. `Maintainer'
  732.      This line should contain a single name/address as in the Author
  733.      line, or an address only, or the string `jwe'.  If there is no
  734.      maintainer line, the person(s) in the Author field are presumed to
  735.      be the maintainers.  The example above is mildly bogus because the
  736.      maintainer line is redundant.
  737.      The idea behind the `Author' and `Maintainer' lines is to make
  738.      possible a function to "send mail to the maintainer" without
  739.      having to mine the name out by hand.
  740.      Be sure to surround the network address with `<...>' if you
  741.      include the person's full name as well as the network address.
  742. `Created'
  743.      This optional line gives the original creation date of the file.
  744.      For historical interest only.
  745. `Version'
  746.      If you wish to record version numbers for the individual Octave
  747.      program, put them in this line.
  748. `Adapted-By'
  749.      In this header line, place the name of the person who adapted the
  750.      library for installation (to make it fit the style conventions, for
  751.      example).
  752. `Keywords'
  753.      This line lists keywords.  Eventually, it will be used by an
  754.      apropos command to allow people will find your package when
  755.      they're looking for things by topic area.  To separate the
  756.      keywords, you can use spaces, commas, or both.
  757.    Just about every Octave function ought to have the `Author' and
  758. `Keywords' header comment lines.  Use the others if they are
  759. appropriate.  You can also put in header lines with other header
  760. names--they have no standard meanings, so they can't do any harm.
  761. File: octave,  Node: Trouble,  Next: Installation,  Prev: Tips,  Up: Top
  762. Known Causes of Trouble
  763. ***********************
  764.    This section describes known problems that affect users of Octave.
  765. Most of these are not Octave bugs per se--if they were, we would fix
  766. them.  But the result for a user may be like the result of a bug.
  767.    Some of these problems are due to bugs in other software, some are
  768. missing features that are too much work to add, and some are places
  769. where people's opinions differ as to what is best.
  770. * Menu:
  771. * Actual Bugs::                 Bugs we will fix later.
  772. * Reporting Bugs::
  773. * Bug Criteria::
  774. * Bug Lists::
  775. * Bug Reporting::
  776. * Sending Patches::
  777. * Service::
  778. File: octave,  Node: Actual Bugs,  Next: Reporting Bugs,  Prev: Trouble,  Up: Trouble
  779. Actual Bugs We Haven't Fixed Yet
  780. ================================
  781.    * Output that comes directly from Fortran functions is not sent
  782.      through the pager and may appear out of sequence with other output
  783.      that is sent through the pager.  One way to avoid this is to force
  784.      pending output to be flushed before calling a function that will
  785.      produce output from within Fortran functions.  To do this, use the
  786.      command
  787.           fflush (stdout)
  788.      Another possible workaround is to use the command
  789.           page_screen_output = "false"
  790.      to turn the pager off.
  791.    * If you get messages like
  792.           Input line too long
  793.      when trying to plot many lines on one graph, you have probably
  794.      generated a plot command that is too larger for `gnuplot''s
  795.      fixed-length buffer for commands.  Splitting up the plot command
  796.      doesn't help because replot is implemented in gnuplot by simply
  797.      appending the new plotting commands to the old command line and
  798.      then evaluating it again.
  799.      You can demonstrate this `feature' by running gnuplot and doing
  800.      something like
  801.             plot sin (x), sin (x), sin (x), ... lots more ..., sin (x)
  802.      and then
  803.             replot sin (x), sin (x), sin (x), ... lots more ..., sin (x)
  804.      after repeating the replot command a few times, gnuplot will give
  805.      you an error.
  806.      Also, it doesn't help to use backslashes to enter a plot command
  807.      over several lines, because the limit is on the overall command
  808.      line length, once the backslashed lines are all pasted together.
  809.      Because of this, Octave tries to use as little of the command-line
  810.      length as possible by using the shortest possible abbreviations for
  811.      all the plot commands and options.  Unfortunately, the length of
  812.      the temporary file names is probably what is taking up the most
  813.      space on the command line.
  814.      You can buy a little bit of command line space by setting the
  815.      environment variable `TMPDIR' to be "." before starting Octave, or
  816.      you can increase the maximum command line length in gnuplot by
  817.      changing the following limits in the file plot.h in the gnuplot
  818.      distribution and recompiling gnuplot.
  819.           #define MAX_LINE_LEN 32768  /* originally 1024 */
  820.           #define MAX_TOKENS 8192     /* originally 400 */
  821.      Of course, this doesn't really fix the problem, but it does make it
  822.      much less likely that you will run into trouble unless you are
  823.      putting a very large number of lines on a given plot.
  824.    A list of ideas for future enhancements is distributed with Octave.
  825. See the file `PROJECTS' in the top level directory in the source
  826. distribution.
  827. File: octave,  Node: Reporting Bugs,  Next: Bug Criteria,  Prev: Actual Bugs,  Up: Trouble
  828. Reporting Bugs
  829. ==============
  830.    Your bug reports play an essential role in making Octave reliable.
  831.    When you encounter a problem, the first thing to do is to see if it
  832. is already known.  *Note Trouble::.  If it isn't known, then you should
  833. report the problem.
  834.    Reporting a bug may help you by bringing a solution to your problem,
  835. or it may not.  In any case, the principal function of a bug report is
  836. to help the entire community by making the next version of Octave work
  837. better.  Bug reports are your contribution to the maintenance of Octave.
  838.    In order for a bug report to serve its purpose, you must include the
  839. information that makes it possible to fix the bug.
  840.    If you have Octave working at all, the easiest way to prepare a
  841. complete bug report is to use the Octave function `bug_report'.  When
  842. you execute this function, Octave will prompt you for a subject and then
  843. invoke the editor on a file that already contains all the configuration
  844. information.  When you exit the editor, Octave will mail the bug report
  845. for you.
  846. * Menu:
  847. * Bug Criteria::
  848. * Where: Bug Lists.             Where to send your bug report.
  849. * Reporting: Bug Reporting.     How to report a bug effectively.
  850. * Patches: Sending Patches.     How to send a patch for Octave.
  851. File: octave,  Node: Bug Criteria,  Next: Bug Lists,  Prev: Reporting Bugs,  Up: Trouble
  852. Have You Found a Bug?
  853. =====================
  854.    If you are not sure whether you have found a bug, here are some
  855. guidelines:
  856.    * If Octave gets a fatal signal, for any input whatever, that is a
  857.      bug.  Reliable interpreters never crash.
  858.    * If Octave produces incorrect results, for any input whatever, that
  859.      is a bug.
  860.    * Some output may appear to be incorrect when it is in fact due to a
  861.      program whose behavior is undefined, which happened by chance to
  862.      give the desired results on another system.  For example, the
  863.      range operator may produce different results because of
  864.      differences in the way floating point arithmetic is handled on
  865.      various systems.
  866.    * If Octave produces an error message for valid input, that is a bug.
  867.    * If Octave does not produce an error message for invalid input,
  868.      that is a bug.  However, you should note that your idea of
  869.      "invalid input" might be my idea of "an extension" or "support for
  870.      traditional practice".
  871.    * If you are an experienced user of programs like Octave, your
  872.      suggestions for improvement are welcome in any case.
  873. File: octave,  Node: Bug Lists,  Next: Bug Reporting,  Prev: Bug Criteria,  Up: Trouble
  874. Where to Report Bugs
  875. ====================
  876.    If you have Octave working at all, the easiest way to prepare a
  877. complete bug report is to use the Octave function `bug_report'.  When
  878. you execute this function, Octave will prompt you for a subject and then
  879. invoke the editor on a file that already contains all the configuration
  880. information.  When you exit the editor, Octave will mail the bug report
  881. for you.
  882.    If for some reason you cannot use Octave's `bug_report' function,
  883. send bug reports for Octave to (bug-octave@bevo.che.wisc.edu).
  884.    *Do not send bug reports to `help-octave'*.  Most users of Octave do
  885. not want to receive bug reports.  Those that do have asked to be on the
  886. mailing list.
  887.    As a last resort, send bug reports on paper to:
  888.      Octave Bugs c/o John W. Eaton
  889.      University of Wisconsin-Madison
  890.      Department of Chemical Engineering
  891.      1415 Engineering Drive
  892.      Madison, Wisconsin 53706  USA
  893. File: octave,  Node: Bug Reporting,  Next: Sending Patches,  Prev: Bug Lists,  Up: Trouble
  894. How to Report Bugs
  895. ==================
  896.    Send bug reports for Octave to one of the addresses listed in *Note
  897. Bug Lists::.
  898.    The fundamental principle of reporting bugs usefully is this:
  899. *report all the facts*.  If you are not sure whether to state a fact or
  900. leave it out, state it!
  901.    Often people omit facts because they think they know what causes the
  902. problem and they conclude that some details don't matter.  Thus, you
  903. might assume that the name of the variable you use in an example does
  904. not matter.  Well, probably it doesn't, but one cannot be sure.
  905. Perhaps the bug is a stray memory reference which happens to fetch from
  906. the location where that name is stored in memory; perhaps, if the name
  907. were different, the contents of that location would fool the
  908. interpreter into doing the right thing despite the bug.  Play it safe
  909. and give a specific, complete example.
  910.    Keep in mind that the purpose of a bug report is to enable someone to
  911. fix the bug if it is not known. Always write your bug reports on the
  912. assumption that the bug is not known.
  913.    Sometimes people give a few sketchy facts and ask, "Does this ring a
  914. bell?"  This cannot help us fix a bug.  It is better to send a complete
  915. bug report to begin with.
  916.    Try to make your bug report self-contained.  If we have to ask you
  917. for more information, it is best if you include all the previous
  918. information in your response, as well as the information that was
  919. missing.
  920.    To enable someone to investigate the bug, you should include all
  921. these things:
  922.    * The version of Octave.  You can get this by noting the version
  923.      number that is printed when Octave starts, or running it with the
  924.      `-v' option.
  925.    * A complete input file that will reproduce the bug.
  926.      A single statement may not be enough of an example--the bug might
  927.      depend on other details that are missing from the single statement
  928.      where the error finally occurs.
  929.    * The command arguments you gave Octave to execute that example and
  930.      observe the bug.  To guarantee you won't omit something important,
  931.      list all the options.
  932.      If we were to try to guess the arguments, we would probably guess
  933.      wrong and then we would not encounter the bug.
  934.    * The type of machine you are using, and the operating system name
  935.      and version number.
  936.    * The command-line arguments you gave to the `configure' command when
  937.      you installed the interpreter.
  938.    * A complete list of any modifications you have made to the
  939.      interpreter source.
  940.      Be precise about these changes--show a context diff for them.
  941.    * Details of any other deviations from the standard procedure for
  942.      installing Octave.
  943.    * A description of what behavior you observe that you believe is
  944.      incorrect.  For example, "The interpreter gets a fatal signal,"
  945.      or, "The output produced at line 208 is incorrect."
  946.      Of course, if the bug is that the interpreter gets a fatal signal,
  947.      then one can't miss it.  But if the bug is incorrect output, we
  948.      might not notice unless it is glaringly wrong.
  949.      Even if the problem you experience is a fatal signal, you should
  950.      still say so explicitly.  Suppose something strange is going on,
  951.      such as, your copy of the interpreter is out of synch, or you have
  952.      encountered a bug in the C library on your system.  Your copy
  953.      might crash and the copy here would not.  If you said to expect a
  954.      crash, then when the interpreter here fails to crash, we would
  955.      know that the bug was not happening.  If you don't say to expect a
  956.      crash, then we would not know whether the bug was happening.  We
  957.      would not be able to draw any conclusion from our observations.
  958.      Often the observed symptom is incorrect output when your program
  959.      is run.  Unfortunately, this is not enough information unless the
  960.      program is short and simple.  It is very helpful if you can
  961.      include an explanation of the expected output, and why the actual
  962.      output is incorrect.
  963.    * If you wish to suggest changes to the Octave source, send them as
  964.      context diffs.  If you even discuss something in the Octave source,
  965.      refer to it by context, not by line number, because the line
  966.      numbers in the development sources probably won't match those in
  967.      your sources.
  968.    Here are some things that are not necessary:
  969.    * A description of the envelope of the bug.
  970.      Often people who encounter a bug spend a lot of time investigating
  971.      which changes to the input file will make the bug go away and
  972.      which changes will not affect it.  Such information is usually not
  973.      necessary to enable us to fix bugs in Octave, but if you can find
  974.      a simpler example to report *instead* of the original one, that is
  975.      a convenience.  Errors in the output will be easier to spot,
  976.      running under the debugger will take less time, etc. Most Octave
  977.      bugs involve just one function, so the most straightforward way to
  978.      simplify an example is to delete all the function definitions
  979.      except the one in which the bug occurs.
  980.      However, simplification is not vital; if you don't want to do
  981.      this, report the bug anyway and send the entire test case you used.
  982.    * A patch for the bug.  Patches can be helpful, but if you find a
  983.      bug, you should report it, even if you cannot send a fix for the
  984.      problem.
  985.